#pragma once

//#define NDEBUG
#include <assert.h>

//#define NOMINMAX
#include <windows.h>

#include <mmsystem.h>
#include <dinput.h>
//errors
#define CheckError(result)   if(FAILED(result)){return result;}
#define CheckErrorBool(result)   if(FAILED(result)){return false;}
#define CheckErrorVoid(result)   if(FAILED(result)){return;}
#define CheckErrorNULL(result)   if(FAILED(result)){return NULL;}
#define CheckErrorBoolNULL(result)   if(result == false){return NULL;}
#define CheckNULLBool(result)   if(result == false){return NULL;}
#define CheckGDIERROR(status) { if (status != Gdiplus::Ok){ _ASSERT(false);return false;}}
#define CheckNULL(status) { if (!status){ return;}}
#define CheckNULLNULL(status) { if (!status){ return NULL;}}

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)       { if (p) { delete (p);     (p)=NULL; } }
#endif    
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p);   (p)=NULL; } }
#endif    
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if (p) { (p)->Release(); (p)=NULL; } }
#endif

//set get
#define SET_ACCESSOR( x, y )       inline void Set##y( x t )   { ##y = t; };
#define GET_ACCESSOR( x, y )       inline x Get##y()           { return  y; };
#define GET_SET_ACCESSOR( x, y )   SET_ACCESSOR( x, y ) GET_ACCESSOR( x, y )

#define SETP_ACCESSOR( x, y )      inline void Set##y( x* t )  { ##y = *t; };
#define GETP_ACCESSOR( x, y )      inline x* Get##y()          { return &y; };
#define GETP_SETP_ACCESSOR( x, y ) SETP_ACCESSOR( x, y ) GETP_ACCESSOR( x, y )

//misc
#define RelativeToFullPath(fileName, dest){ char a[500]; strcpy(a,"C:/Users/tpastor/Documents/Visual Studio 2008/Projects/CudaTestes/DX10Engine/");  strcat(a,fileName); dest = a; }
#define DEFAULTTEXTURE "DEFAULTTEX"

// Direct3D11 includes
#include <d3dcommon.h>
#include <dxgi.h>
#include <d3d11.h>
#include <d3dcompiler.h>
#include <d3dx11.h>
#include <d3dcommon.h>
#include <xnamath.h>
#include <time.h>
#include <mmsystem.h>

#pragma comment(lib, "winmm.lib")
#pragma comment (lib, "d3d11.lib")  
#pragma comment (lib, "d3dx11.lib")        
#pragma comment (lib, "dxgi.lib")
#pragma comment (lib, "PhysXLoader.lib")
#pragma comment (lib, "NxCharacter.lib")

#pragma warning(disable : 4482)


inline UINT CBSize(UINT size)
{
    UINT cbsize = size + (16 - (size % 16));
    return cbsize;
}

inline WCHAR* ToWCHAR(const char* texto)
{
	int buffSize = (int)strlen(texto) + 1;
	WCHAR* text = new wchar_t[buffSize];
	MultiByteToWideChar(CP_ACP, 0, texto, buffSize, text, buffSize);	
	return text;
}
inline XMMATRIX* CREATEXMMATRIX()
{
	return (XMMATRIX* )_aligned_malloc(sizeof(XMMATRIX),16);
}

inline void RELEASEXMMATRIX(XMMATRIX* pt)
{
	_aligned_free(pt);
}

struct BitmapFileData
{
	~BitmapFileData(void)
	{
		delete [] data;
	}
	XMFLOAT3* data;
	long width;
	long height;

	void NormalizeYData(float normalizeFactor)
	{
		int i, j;

		for(j=0; j<height; j++)
		{
			for(i=0; i<width; i++)
			{
				data[(height * j) + i].y /= normalizeFactor;
			}
		}
	
	}
};